package listener.other;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TaskEventManager {

    private static final TaskEventManager taskEventManager = new TaskEventManager();

    private static final Map<Integer, List<TaskEvent>> taskEventMap = new HashMap<>();

    public static TaskEventManager getInstance() {
        return taskEventManager;
    }

    public void addEvent(int eventId, TaskEvent taskEvent) {
        List<TaskEvent> achieveEvents = taskEventMap.computeIfAbsent(eventId, k -> new ArrayList<>());
        achieveEvents.add(taskEvent);
    }

    public void taggerEvent(int eventId, int process) {
        List<TaskEvent> achieveEvents = taskEventMap.get(eventId);
        if (achieveEvents == null || achieveEvents.isEmpty()) {
            return;
        }
        achieveEvents.forEach(e -> {
            if (e.taggerEvent(eventId, process)) {
                System.out.println("触发任务：" + e.getId());
            }
        });
    }

}
